﻿using System.Windows;
using System.Windows.Input;
using Utils.Wpf;

namespace StockAnalyst2
{
	public class MainWindowStateVM : ViewModelBase
	{
		#region Attributes

		private WindowState _previousState;
		private WindowState _state;

		private bool _visible;

		#endregion

		#region Properties

		public WindowState State
		{
			get
			{
				return _state;
			}
			set
			{
				if (_state != value)
				{
					_previousState = _state;
					_state = value;
					base.OnPropertyChanged("State");

					this.IsVisible = _state != WindowState.Minimized;
				}
			}
		}

		public bool IsVisible
		{
			get
			{
				return _visible;
			}
			set
			{
				if (_visible != value)
				{
					_visible = value;
					this.OnPropertyChanged("IsVisible");
					this.OnPropertyChanged("IsIconVisible");
				}
			}
		}

		public Visibility IsIconVisible
		{
			get
			{
				return _visible ? Visibility.Collapsed : Visibility.Visible;
			}
		}

		public ICommand MaximizeCommand { get; set; }

		#endregion

		#region Public Methods

		public MainWindowStateVM()
		{
			this.MaximizeCommand = new DelegateCommand(this.ExecuteMaximize, this.CanExecuteMaximize);
			this.IsVisible = true;
			this.State = WindowState.Maximized;
		}

		#endregion

		#region Private Methods

		private void ExecuteMaximize()
		{
			this.State = _previousState;
			this.IsVisible = true;
		}

		private bool CanExecuteMaximize()
		{
			return !this.IsVisible;
		}

		#endregion
	}
}